/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLSTDDEF_H
#define PLSTDDEF_H

#include <pltypes.h>

/**
 * NULL define.
 */
#ifndef __cplusplus
#if defined NULL
#undef NULL
#endif
#define NULL ((void *)0)
#else
#if defined NULL
#undef NULL
#endif
#define NULL 0
#endif

/**
 * Macro to disable the unused parameter warning.
 *
 * @ingroup lang
 */
#define PLUNUSED(x) (void)x;

/**
 * Offset of member MEMBER in a struct of type TYPE.
 */
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)

/**
 * Deprecated function/variable/type
 */
#ifndef DEPRECATED
#define DEPRECATED __attribute__((deprecated))
#endif

/**
 * Function does not return
 */
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif

/**
 * Function does not have a side-effect (except for the return value)
 */
#ifndef PURE
#define PURE __attribute__((pure))
#endif

/**
 * Function does not have a side-effect and does only depend on its arguments
 */
#ifndef CONST
#define CONST __attribute__((const))
#endif

/**
 * Functions that should always be inlined
 */
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE __attribute__((always_inline))
#endif

/**
 * Specific alignment for a type/variable
 */
#ifndef ALIGN
#define ALIGN(x) __attribute__((aligned(x)))
#endif

/**
 * No padding for a type/variable
 */
#ifndef PACKED
#define PACKED __attribute__((packed))
#endif

/**
 * The type may alias
 */
#ifndef MAY_ALIAS
#define MAY_ALIAS __attribute__((may_alias))
#endif

/**
 * The expression is very likely to be true
 */
#ifndef LIKELY
#define LIKELY(exp) __builtin_expect(!!(exp), 1)
#endif

/**
 * The expression is very unlikely to be true
 */
#ifndef UNLIKELY
#define UNLIKELY(exp) __builtin_expect(!!(exp), 0)
#endif

/**
 * Pack initialisation functions into a special section that could be freed after
 * the kernel initialisation is finished
 */
#ifndef INITIALISATION_ONLY
#define INITIALISATION_ONLY __attribute__((__section__(".init.text")))
#endif

/**
 * Pack initialisation functions into a special section that could be freed after
 * the kernel initialisation is finished
 */
#ifndef INITIALISATION_ONLY_DATA
#define INITIALISATION_ONLY_DATA __attribute__((__section__(".init.data")))
#endif

#endif
